package com.x.ant.dao;

import com.x.ant.model.Line;
import com.x.framework.dao.BaseDao;
import org.springframework.stereotype.Repository;

import java.util.ArrayList;
import java.util.List;

@Repository
public class LineDao extends BaseDao {

    private final static String selectLineListSql = "SELECT T1.* FROM ANT_LINE T1 WHERE T1.DEPT_ID = ? ";
    public List<Line> selectLineList(Line line) throws Exception{
        StringBuilder sb = new StringBuilder(selectLineListSql);
        List params = new ArrayList();
        params.add(line.getDeptId());
        if (this.isString(line.getLineId())) {
            sb.append("AND T1.LINE_ID = ?");
            params.add(line.getLineId());
        }
        return this.queryForList(sb.toString(), Line.class, params, line);
    }

    private final static String selectLineNumSql = "SELECT COUNT(1) FROM ANT_LINE T1 WHERE T1.DEPT_ID = ? ";
    public int selectLineNum(Line line) throws Exception{
        StringBuilder sb = new StringBuilder(selectLineNumSql);
        List params = new ArrayList();
        params.add(line.getDeptId());
        if (this.isString(line.getLineId())) {
            sb.append("AND T1.LINE_ID = ?");
            params.add(line.getLineId());
        }
        return this.queryForInt(sb.toString(), params);
    }

    private final static String updateLineTruckNumSql = "UPDATE ANT_LINE T1 SET T1.LINE_TRUCK_NUM = T1.LINE_TRUCK_NUM + 1 WHERE T1.LINE_ID = ? ";
    public void updateLineTruckNum(Line line) {
        Object[] params = {line.getLineId()};
        this.execute(updateLineTruckNumSql, params);
    }
}
